﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Domain.Interface;
using Domain.Model;
using Newtonsoft.Json;
using WebAPI.Attributes;

namespace WebAPI.Controllers
{
    public class FuJiaXiangController : ApiController
    {
        public IPingShenCaoZuo _IPingShenCaoZuo { set; get; }
        [HttpGet]
        public List<Domain_FuJiaXiang> GetFuJiaXiangs()
        {
            var str = _IPingShenCaoZuo.GetFuJiaXiangs();
            return JsonConvert.DeserializeObject<List<Domain_FuJiaXiang>>(str);
        }
        [HttpPost, WriteFileExceptionAspect]
        public string SaveFuJiaXiang([FromBody] Domain_FuJiaXiang model)
        {
            var str = JsonConvert.SerializeObject(model);
            _IPingShenCaoZuo.CreateFuJiaXiang(model.fjxmc, model.fjxfz);
            return str;
        }

        [HttpGet]
        public void DelFuJiaXiang(int fjxid)
        {
            _IPingShenCaoZuo.DelFuJiaXiang(fjxid);
        }
        /// <summary>
        /// 向MyKaoHeBiao里添加附加项
        /// </summary>
        /// <param name="mkhbid"></param>
        /// <param name="xmid">xmid是附加项的ID</param>
        /// <param name="fz"></param>
        /// <param name="username"></param>
        [HttpGet]
        public void AddMyKHBFJX(int mkhbid, int xmid, decimal fz, string username)
        {
            _IPingShenCaoZuo.MyKaoHeBiaoAddFuJiaXiang(username,mkhbid,xmid,fz);
        }

        /// <summary>
        /// 删除MyKaoHeBiao里的附加项
        /// </summary>
        /// <param name="mkhbid"></param>
        /// <param name="fjxid">fjxid是MyKaoHeBiao_FuJiaXiang中的主键ID</param>
        [HttpGet]
        public void DelMyKHBFJX(int mkhbid, int fjxid)
        {
            _IPingShenCaoZuo.MyKaoHeBiaoDelFuJiaXiang(fjxid,mkhbid);
        }
        /// <summary>
        /// 获取考核表附加项列表
        /// </summary>
        /// <param name="mkhbid"></param>
        /// <returns></returns>
        [HttpGet]
        public List<Domain_MyKaoHeBiaoFuJiaBiao> GetMyKHBFJXs(int mkhbid)
        {
            var str = _IPingShenCaoZuo.GetMyKaoHeBiaoFuJiaXiangs(mkhbid);
            return JsonConvert.DeserializeObject<List<Domain_MyKaoHeBiaoFuJiaBiao>>(str);
        }
    }
}
